<?php

/**

 * [WeEngine System] Copyright (c) 2014 WE7.CC

 * WeEngine is NOT a free software, it under the license terms, visited http://www.qincewang.com/ for more details.

 */

defined('IN_IA') or exit('Access Denied');





function app_navs($type = 'home', $multiid = 0, $section = 0) {

	global $_W;

	$pos = array();

	$pos['home'] = 1;

	$pos['profile'] = 2;

	$pos['shortcut'] = 3;

	if (empty($multiid) && $type != 'profile') {

		load()->model('account');

		$setting = uni_setting($_W['uniacid'], array('default_site'));

		$multiid = $setting['default_site'];

	}

	$sql = "SELECT id,name, description, url, icon, css, position, module FROM " . tablename('site_nav') . " WHERE position = '{$pos[$type]}' AND status = 1 AND uniacid = '{$_W['uniacid']}' AND multiid = '{$multiid}' ORDER BY displayorder DESC, id ASC";

	$navs = pdo_fetchall($sql);

	if (!empty($navs)) {

		foreach ($navs as &$row) {

			if (!strexists($row['url'], 'tel:') && !strexists($row['url'], '://') && !strexists($row['url'], 'www') && !strexists($row['url'], 'i=')) {

				$row['url'] .= strexists($row['url'], '?') ? "&i={$_W['uniacid']}" : "?i={$_W['uniacid']}";

			}

			if (is_serialized($row['css'])) {

				$row['css'] = unserialize($row['css']);

			}

			if (empty($row['css']['icon']['icon'])) {

				$row['css']['icon']['icon'] = 'fa fa-external-link';

			}

			if ($row['position'] == '3') {

				if (!empty($row['css'])) {

					unset($row['css']['icon']['font-size']);

				}

			}

			$row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";

			$row['css']['name'] = "color:{$row['css']['name']['color']};";

		}

		unset($row);

	}

	return $navs;

}

